macroScript Bip_Explorer
	category:"monsterBlues"
	buttontext:"Bip_Explorer"
	tooltip:"Bip_Explorer"
(
global BIPExplorerTool


(

------------------------------------
-- CREATES DIALOG AND KILLS EXISTING
------------------------------------

if BIPExplorerTool != undefined do ( closerolloutfloater BIPExplorerTool )
BIPExplorerTool = newrolloutfloater "BIP Explorer" 230 467

rollout TRIabout "About"
(
		label info1 "BIP Explorer" align:#center
		label info2 "By Juan Martinez" align:#center
)

--****************************
-- BIP Explorer START
--****************************

rollout TRI_Mocap "BIP Explorer"
(

local BIPpath = undefined
local BIPsavename = undefined
local SceneList = #()


	button BipFilePath "Bip File Path" width:144
	group "MoCap List" ( 
		listbox SceneListbox items:SceneList height:22
		button loadBIP "Load" enabled:false width:65 height:20 across:2
		button saveBIP "Save" enabled:false width:65 height:20
		button moveBIP "Move to Origin" enabled:false width:90 height:20
	)

on BipFilePath pressed do
(
	NewBIPpath = ""
	BIPpath = ""
	BIPsavename = undefined
	SceneList = #()
	BIPpath = getsavepath caption:"Pick Folder"
	
	if BIPpath != undefined then (
		BIPparts = filterstring BIPpath "\\"
		
		for i in BIPparts do (
			NewBIPpath = NewBIPpath + i + "/"
			)
		BIPpath = NewBIPpath
		NewBIPpath = NewBIPpath + "*.bip"
		BipFilePath.text = NewBIPpath
		files = getfiles NewBIPpath
		for f in files do (
			BIPname = filenameFromPath f
			append SceneList BIPname
			)
		SceneListbox.items = SceneList
		loadBIP.enabled = true
		saveBIP.enabled = true
		moveBIP.enabled = true
		)
	else BIPpath = ""
)

on SceneListbox doubleClicked BIP do (

	max motion mode
	if $bip01.controller.figureMode == true then (
		messageBox "Please Exit Figure Mode." title:"BIP Explorer"
		)
	else (
		disablesceneredraw()
		BIPname = BIPpath + SceneListbox.items[BIP]
		BIPsavename = SceneListbox.items[BIP]
		biped.LoadBipFile $bip01.controller BIPname
		select $Bip01
		actionMan.executeAction 972555510 "40012"
		clearSelection()
		slidertime = animationrange.start
		enablesceneredraw()
		max views redraw
		)

)

on moveBIP pressed do (

	max motion mode
	disablesceneredraw()
	sliderTime = 0f
	select $Bip01
	Z = biped.getTransform $bip01 #pos
	biped.createLayer $bip01.controller 1 "Move"
	biped.setTransform $bip01 #pos [0,0,Z.z] true
	biped.collapseAtLayer $bip01.controller 0
	clearSelection()
	enablesceneredraw()
	max views redraw

)

on loadBIP pressed do (

	max motion mode
	if $bip01.controller.figureMode == true then (
		messageBox "Please Exit Figure Mode." title:"BIP Explorer"
		)
	else (
		disablesceneredraw()
		BIPname = BIPpath + SceneListbox.selected
		BIPsavename = SceneListbox.selected
		biped.LoadBipFile $bip01.controller BIPname
		select $Bip01
		actionMan.executeAction 972555510 "40012"
		clearSelection()
		slidertime = animationrange.start
		enablesceneredraw()
		max views redraw
		)

)

on saveBIP pressed do (

	max motion mode
	if BIPsavename != undefined then (
		BIPfile = BIPpath + BIPsavename
		biped.SaveBipFile $bip01.controller BIPfile
	)
	else (
		messageBox "Load a BIP file first." title:"BIP Explorer"
	)

)


) -- End BIP Explorer Rollout

--	addRollout head BIPExplorerTool
	addRollout TRI_Mocap BIPExplorerTool
	addRollout TRIabout BIPExplorerTool rolledup:True

	
)  -- End of BIPExplorerTool


)
